package com.liu.service.role;

import com.liu.dao.BaseDao;
import com.liu.dao.role.RoleDao;
import com.liu.dao.role.RoleDaoimpl;
import com.liu.pojo.Role;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.util.List;

public class RoleServiceImpl implements RoleService{
    //引入Dao
    private RoleDao roleDao;

    public RoleServiceImpl() {
        roleDao = new RoleDaoimpl();
    }

    @Override
    public List<Role> getRoleList() throws Exception {
        Connection connection = null;
        List<Role> roleList = null;
        try{
            connection = BaseDao.getConnection();
            roleList = roleDao.getRoleList(connection);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            BaseDao.closeResource(connection,null,null);
        }
        return roleList;
    }
@Test
    public void testGetRoleList() {
        RoleService roleService = new RoleServiceImpl();
        try{
            List<Role> roles = roleService.getRoleList();
            for (Role role : roles) {
                System.out.println(role.getRoleName());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

}
}

